cmake_minimum_required(VERSION 3.24)
project(first)

# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)

#
find_package(PkgConfig REQUIRED)

#
pkg_check_modules(AVFORMAT REQUIRED libavformat)
pkg_check_modules(AVCODEC  REQUIRED libavcodec)
pkg_check_modules(SWSCALE  REQUIRED libswscale)
pkg_check_modules(AVUTIL REQUIRED libavutil)

# 设置 JDK 路径
set(JAVA_HOME /usr/local/jdk1.8.0_333)

# 包含 JNI 头文件
include_directories(${JAVA_HOME}/include)
include_directories(${JAVA_HOME}/include/linux)

# include ffmpeg
include_directories(${AVFORMAT_INCLUDE_DIRS})
include_directories(${AVCODEC_INCLUDE_DIRS})
include_directories(${SWSCALE_INCLUDE_DIRS})
include_directories(${AVUTIL_INCLUDE_DIRS})

# so
link_directories(${PROJECT_SOURCE_DIR}/lib)
link_directories(${AVFORMAT_LIBRARY_DIRS})
link_directories(${AVCODEC_LIBRARY_DIRS})
link_directories(${SWSCALE_LIBRARY_DIRS})
link_directories(${AVUTIL_LIBRARY_DIRS})

# 查找 JVM 库
find_library(JVM_LIBRARY jvm HINTS ${JAVA_HOME}/jre/lib/amd64/server)

# 添加可执行文件
add_executable(first ${PROJECT_SOURCE_DIR}/src/main.cpp)

# 添加源文件
set(SOURCES ${PROJECT_SOURCE_DIR}/src/com_kedacom_NativeCalcMethod.cpp
)
# 指定头文件目录
include_directories(include)

# 生成共享库
add_library(MyLibrary SHARED ${SOURCES})

# 设置库版本
set_target_properties(MyLibrary PROPERTIES VERSION 1.0 SOVERSION 1)

# 链接 JVM 库
target_link_libraries(first ${JVM_LIBRARY} ${AVUTIL_LIBRARIES} ${AVFORMAT_LIBRARIES} ${AVCODEC_LIBRARIES} ${SWSCALE_LIBRARIES})